<%@page import="org.proddevplm.dao.data.designForX.DfXGuidelines"%>
<%@page import="org.proddevplm.dao.data.designForX.DesignForX"%>
<%@page import="java.util.List"%>
<%@page import="org.proddevplm.constants.ControllerConstants"%>
<%@page import="org.proddevplm.business.activity.constants.ActivityConstants" %>

<script>

	$(function(){
		$("button").button();
	})
	
	function submitGuidelines(size){
		var index = 0;
		var list = '';
		
		for(var i=0; i<size; i++){
			$("#guideByDFXId_"+i+" option").each(function(){
				if(this.selected){
					if(index++>0){
						list+='~';
					}
					list+=$(this)[0].value;
				}
			});
		}
		var activityName = $('#activitySelect').val();
		var arguments = "guidelinesList="+list+"&activityName="+activityName;
		ajaxCall("toolsManager", "27", arguments, message);
	}
	
	function message(data){
		alert('Guidelines successfully asigned to this product');
	}
	
	
	function finishActivity(name){
		$("#activityName").val(name);
		document.forms['finishActivityForm'].submit();
	}

</script>


<%
	List<DesignForX> selDFXById = (List)session.getAttribute("selDFXById");
	List<DfXGuidelines> guidelinesByDfXId = (List)session.getAttribute("guidelinesByDfXId");
%>

<table class="tablesorter" style="width:100%; margin-top:10px;" rules="rows" frame="hsides" bordercolor="#DBDBDB">
	<thead>
		<tr>
			<th>Design for X concept</th>
			<th>Design for X guidelines</th>
		</tr>
	</thead>
	<tbody>
		<%for(int i=0; i<selDFXById.size(); i++){
			DesignForX dfx = selDFXById.get(i);%>
			<tr>
				<td style="width:30%"><%=dfx.getDfxName() %></td>
				<td style="width:70%">
					<select name="guideByDFXId_<%=i %>" id="guideByDFXId_<%=i %>" size="6" multiple="multiple" style="width:100%; border:none">
						<%for(int j=0; j<guidelinesByDfXId.size(); j++){
							DfXGuidelines dfxG = guidelinesByDfXId.get(j);
							if(dfxG.getDfx()==dfx){%>
								<option value="<%=dfxG.getId() %>"><%=dfxG.getGuideline() %></option>
							<%} %>
						<%} %>
					</select>
				</td>
			</tr>
		<%}%>
	</tbody>

</table>
<%int size = selDFXById.size(); %>
<div style="width:100%; ">
	<button id="submitGuidelines" name="submitGuidelines" onclick="submitGuidelines('<%=size%>')" style="width:20%; font-size:x-small; font-weight:bold; float:left">Submit selected guidelines</button>
	<button id="finishActivity" name="finishActivity" onclick="finishActivity($('#activitySelect').val())" style="width:20%; font-size:x-small; font-weight:bold; float:right">Finish activity</button>
</div>
<form name="finishActivityForm" method="post" action="/proddev/controller" style="margin:0px">
	<input type = "hidden" name = "<%=ControllerConstants.MANAGER_KEY%>" value = "<%=ControllerConstants.ACTIVITY_MANAGER%>"/>
	<input type = "hidden" name = "<%=ControllerConstants.METHOD_KEY%>" value = "<%=ActivityConstants.CHANGE_STATUS%>"/>
	<input type="hidden" name="activityName" id="activityName">	
</form>